<template>
	<view class="personalInfo  ">

		<view class="personalBox bgWhite radius8">

			<uv-form labelPosition="left" :model="personaModel"  :labelStyle="labelStyle"
				ref="form">
				<uv-form-item label="姓名" borderBottom prop="personaModel.name" labelWidth="140rpx">
					<uv-input inputAlign="right" v-model="personaModel.name" border="none" placeholder="请输入">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="身份证号" borderBottom prop="personaModel.idcode" labelWidth="140rpx">
					<uv-input inputAlign="right" v-model="personaModel.idcode" border="none" placeholder="请输入">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="住址" borderBottom prop="personaModel.address" labelWidth="140rpx">
					<uv-input inputAlign="right" v-model="personaModel.address" border="none" placeholder="请输入">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="上传身份证" labelPosition="top" prop="personaModel.sfz1" labelWidth="160rpx">
					<view class="justify-between align-center">
						<view class="posRelative " @click="upload(1)">
							<image v-if="personaModel.sfz1" class="radius6" :src="personaModel.sfz1" mode=""></image>
							<image v-else src="../../static/images/1.jpg" class="radius5" mode="widthFix"></image>
							<view class="posAbsort textbox">
								上传身份证正面照片
							</view>
						</view>
						<view class="posRelative " @click="upload(2)">
							<image v-if="personaModel.sfz2" class="radius6" :src="personaModel.sfz2" mode=""></image>
							<image v-else src="../../static/images/2.jpg" class="radius5" mode="widthFix"></image>
							<view class="posAbsort textbox">
								上传身份证反面照片
							</view>
						</view>
					</view>
				</uv-form-item>
			</uv-form>
		</view>
		<view class="save_btn"  @click="save">
			{{ status=='4'?'审核中':status=='3'?'重新提交 ':status=='1'?'提交申请 ' :'修改 '}}
		</view>
		<uv-picker ref="areaPicker" :columns="areaRrand" keyName="name" @change="carChange"
			@confirm="areaConfirm"></uv-picker>
	</view>
</template>

<script>
	import operate from '@/common/operate.js'
	export default {
		data() {
			return {
				labelStyle: {
					'height': '87rpx',
					'font-size': "30rpx",
					'color': '#000'
				},
				personaModel: {
					name: "",
					idcode: '',
					address: "",
					sfz1: "",
					sfz2: ""
				},
				personalRules: {
					'name': {
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur', 'change']
					},
					'idcode': {
						type: 'string',
						required: true,
						message: '请填写身份证号',
						trigger: ['blur', 'change']
					},
					'address': {
						type: 'string',
						required: true,
						message: '请填写地址',
						trigger: ['blur', 'change']
					},
					// 'personaModel.sfz1': {
					// 	type: 'string',
					// 	required: true,
					// 	message: '请上传身份证正反面照片',
					// 	trigger: ['blur', 'change']
					// },
					

				},
				areaRrand: [
					[],
					[]
				],
				columnData: [],
				area: "",
				checkboxValue: [],
				cateList: [],
				status:"",
				loading:false
			};
		},
		onReady() {
		},
		onLoad() {
			
			
				
			this.$api.shiminginfo().then(res=>{
				console.log(res)
				this.status=res.data.status
				this.personaModel={
					name: res.data.realname,
					idcode:  res.data.idcode,
					address:  res.data.address,
					sfz1:  res.data.sfz1,
					sfz2:  res.data.sfz2,
				}
			})
		},
		methods: {
			upload(type) {
				let vm = this
				uni.chooseImage({
					sourceType: ['album'],
					count: 1,
					success: function(res) {
						console.log(res)
						vm.$api.uploadImg({
							filePath: res.tempFilePaths[0]
						}).then(res => {
							switch (type) {
								case 1:
									vm.personaModel.sfz1 = res.data.fullurl
									break;
								case 2:
									vm.personaModel.sfz2 = res.data.fullurl
									break;
							
							}
						})
					}
				})
			},
			async save() {
				if(this.status==4) return
				let vm=this
				if (!vm.personaModel.name) return vm.$utils.msg('请输入姓名')
				if (!vm.personaModel.idcode) return vm.$utils.msg('请输入身份证号')
				if (!vm.personaModel.address) return vm.$utils.msg('请输入地址')
				
				if (!vm.personaModel.sfz1) return vm.$utils.msg('请上传身份证正面图片')
				if (!vm.personaModel.sfz2) return vm.$utils.msg('请上传身份证反面图片')
				if(vm.loading) return
				vm.loading=true
					this.$api.userIdentity(this.personaModel).then(res=>{
						console.log(res)
						vm.loading=false
						if(res.code==1){
							uni.showToast({
								title:'操作成功'
							})
							setTimeout(()=>{
								uni.navigateBack()
							},1000)
						}else{
							this.$utils.msg(res.msg)
						}
					})
			},


		}
	}
</script>
<style>
	page {
		background-color: #f5f5f5;
	}
</style>
<style lang="scss" scoped>
	.header {
		margin-top: 52rpx;
		margin-bottom: 40rpx;
		font-weight: 600;
		font-size: 36rpx;
		color: #000000;
		line-height: 36rpx;

	}

	.personalInfo {

		padding: 22rpx;
		position: relative;

		.personalBox {
			padding: 0 32rpx 40rpx;

		}

		.save_btn {
			width: 100%;
			height: 90rpx;
			margin-top: 38rpx;
			margin-bottom: 40rpx;
			background: #49806F;
			border-radius: 12rpx;
			font-size: 32rpx;
			color: #FFFFFF;
			text-align: center;
			line-height: 90rpx;
		}

	}

	button {
		color: #303133;
		font-size: 28rpx;
		text-align: left;
	}

	image {
		width: 300rpx;
		height: 200rpx;

	}

	.textbox {
		width: 300rpx;
		height: 51rpx;
		background: #DFC199;
		border-radius: 0 0 10rpx 10rpx;
		font-weight: 400;
		font-size: 23rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 51rpx;
		bottom: 0;
		left: 0;
	}
</style>